package com.wjf.accesscontrol.ui.setting

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProviders
import com.wjf.accesscontrol.base.MVVMBaseFragment
import com.wjf.accesscontrol.databinding.FragmentSettingBinding
import com.wjf.accesscontrol.ui.TitleBarActivity
import com.wjf.accesscontrol.util.COMMON_FLAG_DATA
import com.wjf.accesscontrol.util.Constant
import com.wjf.accesscontrol.util.JUMP_TO_ActivateFragment
import com.wjf.accesscontrol.util.ToastUtils
import com.wjf.accesscontrol.util.singleClick

/**
 * @Description
 * @Author WuJianFeng
 * @Date 2024/1/31 9:48
 *
 */

class SettingFragment: MVVMBaseFragment<SettingViewModel,FragmentSettingBinding>() {

    companion object{
        fun newInstance(): SettingFragment{
            val activateFragment = SettingFragment()
            return activateFragment
        }
    }

    override fun initViewModel() = ViewModelProviders.of(this).get(SettingViewModel::class.java)


    override fun initViewBinding(inflater: LayoutInflater, container: ViewGroup?) =
        FragmentSettingBinding.inflate(inflater,container,false)

    override fun initData() {
        binding.etMachine.setText(Constant.machineId)
    }
    override fun initClick() {

        binding.tvReturn.singleClick {
            activity?.finish()
        }

        binding.tvSave.singleClick {
            if (binding.etMachine.text.isEmpty()){
                ToastUtils.show("设备编号不能为空")
                return@singleClick
            }
            TitleBarActivity.newInstance(mView.context, JUMP_TO_ActivateFragment, binding.etMachine.text.toString())
        }
    }
}